//
//  FlyDatePickerView.m
//  MedicalProject
//
//  Created by lifayu on 16/12/28.
//  Copyright © 2016年 贵阳飞云科技有限公司. All rights reserved.
//

#import "FlyDatePickerView.h"

@implementation FlyDatePickerView

- (void)awakeFromNib
{
    [super awakeFromNib];
}

+ (void)showInView:(UIView *)view dateModel:(UIDatePickerMode)datePickerModel completionBlock:(Completionblock)block
{
    if(!view)
    {
        view = [UIApplication sharedApplication].keyWindow;
    }
    FlyDatePickerView *datePickerView = (FlyDatePickerView *)[[UINib nibWithNibName:@"FlyDatePickerView" bundle:nil] instantiateWithOwner:self options:nil].firstObject;
    datePickerView.frame = view.bounds;
    datePickerView.datePickerView.datePickerMode = datePickerModel;
    datePickerView.block = block;
    [view addSubview:datePickerView];
}
+ (void)showInView:(UIView *)view dateModel:(UIDatePickerMode)datePickerModel maxDate:(NSDate *)maxDate minDate:(NSDate *)minDate completionBlock:(Completionblock)block
{
    if(!view)
    {
        view = [UIApplication sharedApplication].keyWindow;
    }
    FlyDatePickerView *datePickerView = (FlyDatePickerView *)[[UINib nibWithNibName:@"FlyDatePickerView" bundle:nil] instantiateWithOwner:self options:nil].firstObject;
    datePickerView.frame = view.bounds;
    datePickerView.datePickerView.datePickerMode = datePickerModel;
    datePickerView.block = block;
    if(maxDate)
    {
        datePickerView.datePickerView.maximumDate = maxDate;
    }
    if(minDate)
    {
        datePickerView.datePickerView.minimumDate = minDate;
    }
    [view addSubview:datePickerView];
}

#pragma mark 确定
- (IBAction)clockDetermine:(id)sender
{
    if(_block)
    {
        NSDate *date = _datePickerView.date;
        _block(date);
    }
    [self cancel:nil];
}
#pragma mark 取消
- (IBAction)cancel:(id)sender
{
    [self removeFromSuperview];
}

@end
